home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dosrcss.zip / SNOOP.C < prev   
C/C++ Source or Header  |  1990-07-18  |  4KB  |  131 lines

  1. /*
  2.  *                     Logging of RCS commands co and ci
  3.  */
  4. #ifndef lint
  5.  static char rcsid[]=
  6.  "$Header: /site/tmp/dosrcs/src/RCS/snoop.c,v 5.2 90/07/15 11:35:49 ROOT_DOS Release $ Purdue CS";
  7. #endif
  8. /*******************************************************************
  9.  * This program appends argv[1] to the file SNOOPFILE.
  10.  * To avoid overlaps, it creates a lockfile with name lock in the same
  11.  * directory as SNOOPFILE. SNOOPFILE must be defined in the cc command. 
  12.  * Prints an error message if lockfile doesn't get deleted after
  13.  * MAXTRIES tries.
  14.  *******************************************************************
  15.  */
  16.  
  17. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  18.    Distributed under license by the Free Software Foundation, Inc.
  19.  
  20. This file is part of RCS.
  21.  
  22. RCS is free software; you can redistribute it and/or modify
  23. it under the terms of the GNU General Public License as published by
  24. the Free Software Foundation; either version 1, or (at your option)
  25. any later version.
  26.  
  27. RCS is distributed in the hope that it will be useful,
  28. but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  30. GNU General Public License for more details.
  31.  
  32. You should have received a copy of the GNU General Public License
  33. along with RCS; see the file COPYING.  If not, write to
  34. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  35.  
  36. Report problems and direct all questions to:
  37.  
  38.     rcs-bugs@cs.purdue.edu
  39.  
  40. */
  41.  
  42.  
  43. /* $Log:    snoop.c,v $
  44.  * Revision 5.2  90/07/15  11:35:49  ROOT_DOS
  45.  * DOS version of RCS 4.0 checked in for MODS
  46.  * by lfk@athena.mit.edu
  47.  * Also update to MSC 6.0
  48.  * 
  49.  * Revision 4.4  89/05/01  15:14:00  narten
  50.  * changed copyright header to reflect current distribution rules
  51.  * 
  52.  * Revision 4.3  87/12/18  11:46:52  narten
  53.  * more lint cleanups (Guy Harris)
  54.  * 
  55.  * Revision 4.2  87/10/18  10:41:47  narten
  56.  * Changing version numbers. Changes relative to 1.1 actually relative to 
  57.  * 4.1
  58.  * 
  59.  * Revision 1.2  87/09/24  14:01:41  narten
  60.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  61.  * warnings)
  62.  * 
  63.  * Revision 1.1  84/01/23  14:50:49  kcs
  64.  * Initial revision
  65.  * 
  66.  * Revision 4.1  83/03/28  13:23:42  wft
  67.  * No change; just new revision number.
  68.  * 
  69.  * Revision 3.2  82/12/04  17:14:31  wft
  70.  * Added rcsbase.h, changed SNOOPDIR to SNOOPFILE, reintroduced
  71.  * error message in case of permanent locking.
  72.  * 
  73.  * Revision 3.1  82/10/18  21:22:03  wft
  74.  * Number of polls now 20, no error message if critical section can't
  75.  * be entered.
  76.  * 
  77.  * Revision 2.3  82/07/01  23:49:28  wft
  78.  * changed copyright notice only.
  79.  * 
  80.  * Revision 2.2  82/06/03  20:00:10  wft
  81.  * changed name from rcslog to snoop, replaced LOGDIR with SNOOPDIR.
  82.  * 
  83.  * Revision 2.1  82/05/06  17:55:54  wft
  84.  * Initial revision
  85.  *
  86.  */
  87.  
  88.  
  89. #include "rcsbase.h"
  90. #define fflsbuf _flsbuf
  91. /* undo redefinition of putc in rcsbase.h */
  92.  
  93. char  lockfname[NCPPN];
  94. FILE * logfile;
  95. int lockfile;
  96.  
  97. #define MAXTRIES 20
  98.  
  99. main(argc,argv)
  100. int argc; char * argv[];
  101. /* writes argv[1] to SNOOPFILE and appends a newline. Invoked as follows:
  102.  * rcslog logmessage
  103.  */
  104. {       int tries;
  105.         register char * lastslash, *sp;
  106.  
  107.         VOID strcpy(lockfname,(char *) SNOOPFILE);
  108.         lastslash = sp = lockfname;
  109.         while (*sp) if (*sp++ =='/') lastslash=sp; /* points beyond / */
  110.         VOID strcpy(lastslash,",lockfile");
  111.         tries=0;
  112.         while (((lockfile=creat(lockfname, 000)) == -1) && (tries<=MAXTRIES)) {
  113.                 tries++;
  114.                 sleep(5);
  115.         }
  116.         if (tries<=MAXTRIES) {
  117.                 VOID close(lockfile);
  118.                 if ((logfile=fopen(SNOOPFILE,"a")) ==NULL) {
  119.                         VOID fprintf(stderr,"Can't open logfile %s\n",SNOOPFILE);
  120.                 } else {
  121.                         VOID fputs(argv[1],logfile);
  122.                         VOID putc('\n',logfile);
  123.                         VOID fclose(logfile);
  124.                 }
  125.                 VOID unlink(lockfname);
  126.         } else {
  127.                 VOID fprintf(stderr,"RCS logfile %s seems permanently locked.\n",SNOOPFILE);
  128.                 VOID fprintf(stderr,"Please alert system administrator\n");
  129.         }
  130. }
  131.